package com.xwj.action;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

/**
 * @author xwj
 * @date 2020/11/13
 */
@LocalTCC
public interface StorageTccAction {
    /**
     * 减库存：一阶段
     *
     * @param businessActionContext
     * @param productId
     * @param count
     * @return
     */
    @TwoPhaseBusinessAction(name = "decreaseTccAction", commitMethod = "commitDecrease", rollbackMethod = "rollbackDecrease")
    boolean decreaseTccAction(BusinessActionContext businessActionContext,
                              @BusinessActionContextParameter(paramName = "productId") Long productId,
                              @BusinessActionContextParameter(paramName = "count") Integer count);

    /**
     * 减库存：二阶段提交
     *
     * @param businessActionContext
     * @return
     */
    boolean commitDecrease(BusinessActionContext businessActionContext);

    /**
     * 减库存：二阶段回滚
     *
     * @param businessActionContext
     * @return
     */
    boolean rollbackDecrease(BusinessActionContext businessActionContext);
}
